#include "../src/animal.hpp"
#include "../src/factory.hpp"
#include "../src/cat.hpp"
#include "../src/dog.hpp"
#include <functional>
#include <memory>
#include <iostream>

// 标签到创建函数的签名
using CreateAnimal = std::function<std::unique_ptr<Animal>(const std::string&)>;

int main() {
    Factory<CreateAnimal> farm;

    // 注册工厂方法
    farm.subscribe("CAT", [](const std::string& name) {
        return std::make_unique<Cat>(name);
    });
    farm.subscribe("DOG", [](const std::string& name) {
        return std::make_unique<Dog>(name);
    });

    // 动态创建
    auto simon   = farm.create("CAT", "Simon");
    auto marlowe = farm.create("DOG", "Marlowe");

    // 调用 speak
    simon->speak();    // 输出: I'm Simon the cat!
    marlowe->speak();  // 输出: I'm Marlowe the dog!

    return 0;
}